<template>
  <uni-forms class="login-form" ref="form">
    <uni-forms-item name="name">
      <input
        type="text"
        placeholder="请输入账号"
        class="uni-input-input"
        placeholder-style="color: #818181"
        v-model="data.account"
      />
    </uni-forms-item>
    <uni-forms-item name="name">
      <input
        type="text"
        placeholder="请输入密码"
        class="uni-input-input"
        placeholder-style="color: #818181"
        v-model="data.password"
      />
    </uni-forms-item>
    <button class="submit-button" @click="login">登录</button>
  </uni-forms>
</template>

<script setup>
  import { getLogin } from '../api'
  import { ref } from 'vue'
  import { useCounterStore } from '@/stores/index'
  import { utils } from '@/utils/utils'
  const counterStore = useCounterStore()
  const data = ref({ account: 'sysj001', password: '123456' })
  // const redirectURL = ref('')   // 回跳地址
  // const routeType = ref('')   // 跳转地址方式
  // onLoad((query) => { // 获取地址中的参数
  //   redirectURL.value = query.redirectURL
  //   routeType.value = query.routeType
  // })
  const login = async () => {
    const res = await getLogin(data.value) // 发登录请求，获取token
    counterStore.token = res.data // 存储token
    utils.toast('登录成功', 'success') // 登录成功提示
    uni.switchTab({
      url: '/pages/my/index',
    })
  }
</script>

<style lang="scss" scoped>
  @import './styles.scss';
</style>
